package statistics;

import java.util.ArrayList;

import configuration.parameters.Parameter;

import informationExtractionSystem.InformationExtractor;
import distributedRE.model.DistributedREModel;
import distributedRE.model.Document;
import distributedRE.model.QueryDatabase;
import distributedRE.model.Relation;

public class MeasuredPrecision implements DistributedREStatistic {

	private InformationExtractor ie;
	private Relation r;

	public MeasuredPrecision (InformationExtractor ie, Relation r){
		
		this.ie = ie; 
		this.r = r;
		
	}
	
	public Double getLastSessionStatistic(DistributedREModel dREModel) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Double getQueryDatabaseStatistic(QueryDatabase queryDatabase) {

		ArrayList<Document> documents =  (ArrayList<Document>)queryDatabase.getParameter(Parameter.DOCUMENTS).getValue();
	
		double total = (double)documents.size();
		
		double useful = 0.0;
		
		for (Document document : documents) {
			
			if (ie.isUseful(r,document) == InformationExtractor.USEFUL_VALUE)
				useful++;
				
		}
		
		if (total==0)
			return new Double(0);
		
		return new Double (useful/total);
		
	}


}
